var mysql = require('mysql');
var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'lxs123',
    port: '3306',
    database: 'nodejstest'
});
connection.connect();

//增
/* var  addSql = 'INSERT INTO websites(Id,name,url,alexa,country) VALUES(0,?,?,?,?)';
var  addSqlParams = ['菜鸟工具', 'https://c.runoob.com','23453', 'CN'];
connection.query(addSql,addSqlParams,function (err, result) {
        if(err){
         console.log('失败',err.message);
         return;
        }        
       console.log('INSERT ID:',result.insertId);               
}); */

//删
/* var delSql = 'DELETE FROM websites where id=10';
connection.query(delSql, function (err, result) {
    if (err) {
        console.log('失败', err.message);
        return;
    }
    console.log('DELETE affectedRows', result.affectedRows);
}); */

//改
/* var modSql = 'UPDATE websites SET name = ?,url = ? WHERE Id = ?';
var modSqlParams = ['菜鸟移动站', 'https://m.runoob.com',8];
connection.query(modSql,modSqlParams,function (err, result) {
    if (err) {
        console.log('失败', err.message);
        return;
    }        
    console.log('UPDATE affectedRows',result.affectedRows);
}); */

//查
var sql = 'SELECT * FROM websites where id=1';
connection.query(sql, function (err, result) {
    if (err) {
        console.log('失败', err.message);
        return;
    }

    console.log(result);
    console.log('\n\n');
});


connection.end();